import path from 'path'

const config = {
  projectName: 'flex_code_ui',
  date: '2024-3-11',
  designWidth: 750,
  deviceRatio: {
    640: 2.34 / 2,
    750: 1,
    828: 1.81 / 2
  },
  sourceRoot: 'src',
  outputRoot: 'dist',
  plugins: [],
  defineConstants: {},
  copy: {
    patterns: [],
    options: {}
  },
  alias: {
    '~taro-ui/dist': `~taro-ui/rn`,
    '@': path.resolve(__dirname, '..', 'src'),
    '@flex_code/ui': path.resolve(__dirname, '..', 'src/flex_code/ui'),
    '@flex_code/core': path.resolve(__dirname, '..', 'src/flex_code/core')
  },
  framework: 'react',
  compiler: {
    type: 'webpack5',
    prebundle: {
      exclude: ['taro-ui']
    }
  },
  cache: {
    enable: false // Webpack 持久化缓存配置，建议开启。默认配置请参考：https://docs.taro.zone/docs/config-detail#cache
  },
  mini: {
    postcss: {
      pxtransform: {
        enable: true,
        config: {}
      },
      url: {
        enable: true,
        config: {
          limit: 1024 // 设定转换尺寸上限
        }
      },
      cssModules: {
        enable: false, // 默认为 false，如需使用 css modules 功能，则设为 true
        config: {
          namingPattern: 'module', // 转换模式，取值为 global/module
          generateScopedName: '[name]__[local]___[hash:base64:5]'
        }
      }
    }
  },
  h5: {
    publicPath: '/',
    staticDirectory: 'static',
    postcss: {
      autoprefixer: {
        enable: true,
        config: {}
      },
      cssModules: {
        enable: false, // 默认为 false，如需使用 css modules 功能，则设为 true
        config: {
          namingPattern: 'module', // 转换模式，取值为 global/module
          generateScopedName: '[name]__[local]___[hash:base64:5]'
        }
      }
    },
    esnextModules: ['taro-ui']
  },
  rn: {
    // appName: 'taroDemo',
    // appName: 'taro',
    // appName: 'flex_code_ui',
    // entry: 'app',
    output: {
      ios: './ios/main.jsbundle',
      iosAssetsDest: './ios',
      android: './android/app/src/main/assets/index.android.bundle',
      androidAssetsDest: './android/app/src/main/res',
      // iosSourceMapUrl: '','~taro-ui/dist': `~taro-ui/rn`
      iosSourcemapOutput: './ios/main.map'
      // iosSourcemapSourcesRoot: '',
      // androidSourceMapUrl: '',
      // androidSourcemapSourcesRoot: '',
    },
    // postcss: {
    //   cssModules: {
    //     enable: false, // 默认为 false，如需使用 css modules 功能，则设为 true
    //   }
    // },
    // resolve: {
    //   include: ['flex_code_design', 'taro-ui']
    // },
  }
}

module.exports = function (merge) {
  if (process.env.NODE_ENV === 'development') {
    return merge({}, config, require('./dev'))
  }
  return merge({}, config, require('./prod'))
}
